package com.zp.datax.core;

import com.zp.datax.core.model.DataxJobTrigger;

import java.util.Objects;

/**
 * id条件处理器
 *
 * @author bruce
 * @date 2019-07-15
 */
public class StartIdCondition extends Condition {

    protected StartIdCondition(Condition condition) {
        super(condition);
    }

    @Override
    public Object[] append(String str) {

        Object[] objarray = getObjarray(str);
        String condition = Objects.toString(objarray[0]);

        if (!str.contains("startId")) {
            return objarray;
        }

        DataxJobTrigger dataxJobTrigger = getDataxJobTrigger();
        Long minid = dataxJobTrigger.getMinid();
        Long maxid = dataxJobTrigger.getMaxid();
        if (minid.compareTo(0L) == 1
                && maxid.compareTo(0L) == 1
                && maxid.compareTo(minid) == 1) {
            minid = maxid;
        }

        objarray[0] = String.format("%sstartId=%d,", condition, minid);
        dataxJobTrigger.setMinid(minid);

        return objarray;
    }
}
